|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Help with Java programs.
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||||
|
Commodore 64
![]()
Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228
Rep: 89
![]() Unique Rep: 72
Trader Rating: 9
|
Hey guys, I;m currently taking a course in Java and I don't remember how to do this.
1. Write a swtich statement that follows the menu given below. Enter A to print the name Alan Enter B to print the name Bob Enter C to print the name Carl Enter D to print the name David If anything else if entered print "Invalid Choice" How would I do that? And for number 2. 2.Write a program that will aloow a user to input an integer between 1 and 25(inclusive) and then print a line of asteriks (*), using a for loop, that uses the input value as the length of the line.. Example 1 Input: Please enter and integer from 1 to 25: 5 Output: ***** Example 2 Input: Please enter an integer from 1 to 25: 7 Output: ******* Help guys? This is in Java using Eclipse.
__________________
Quote:
Quote:
Xfire : gormogon : [OCN] Teh Root SteamID: [OCN] Teh Root
|
|||||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
.
![]() |
It would be helpful if you posted what you have so far. That way no one is actually doing this assignment for you. This is fairly simple stuff, so if you post what you've got so far, it won't be hard to help walk you through it.
__________________
Imaging with Windows PE Please keep the OCN Terms of Service in mind when posting.
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||||
|
Commodore 64
![]()
Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228
Rep: 89
![]() Unique Rep: 72
Trader Rating: 9
|
How do I create a string in Eclipse?
__________________
Quote:
Quote:
Xfire : gormogon : [OCN] Teh Root SteamID: [OCN] Teh Root
|
|||||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
.
![]() |
Creating a string is not based on what program you're using. It's simply java.
Code:
String str = new String("This is a String");
__________________
Imaging with Windows PE Please keep the OCN Terms of Service in mind when posting.
|
|||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||||
|
Commodore 64
![]()
Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228
Rep: 89
![]() Unique Rep: 72
Trader Rating: 9
|
but I have this.... for the first one...
import java.util.*; public class names { static Scanner Scanner = new Scanner(System.in); /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.print("Enter A to print the name Alan: "); string names = Scanner.nextString(); } } To enter a character is it string or a char?
__________________
Quote:
Quote:
Xfire : gormogon : [OCN] Teh Root SteamID: [OCN] Teh Root
|
|||||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||||||||
|
Commodore 64
![]()
Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228
Rep: 89
![]() Unique Rep: 72
Trader Rating: 9
|
I only need to actually write the switch statement for the first one, the second one I have to write.
__________________
Quote:
Quote:
Xfire : gormogon : [OCN] Teh Root SteamID: [OCN] Teh Root
|
|||||||||||||||
|
|
|
|
|
#7 (permalink) | |||||||||||
|
Overclocker
![]()
Join Date: Aug 2007
Location: *Cape Town* FTW!
Posts: 1,746
Rep: 143
![]() ![]() Unique Rep: 110
Trader Rating: 0
|
Buddy this is easy stuff, would help you but im on my cellphone now. Goodluck learning the java language! Its pretty neat,i just wrote my IT programming finals a few days ago (now that was crap i tell you!).
Cheers
__________________
![]() Don't listen to crap! Listen to real music. Listen to TRANCE!!![]() ![]() I WANT TO FOLD FOR OCN BUT MY CELERY JUST AINT CUTTING IT!![]() Best OCN flame pics!![]() Best game ever!![]() ...┌∩┐(◣_◢)┌∩┐...![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
|||||||||||
|
|
|
|
|
#8 (permalink) | ||||||||||||||
|
The CanAsian
![]() |
Quote:
string letter = joptionpane.showInputDialog("Input whatever letter"); string lower = letter.toLowerCase(); if (lower==a) System.out.println("Alan"); else if (lower == b) System.out.println("Bob"); thats how you do the first one. relatively simple stuff. the second one is just a loop where the user enters a number (15 for example) and you get that number using integer number = JOptionPane.showInputDialog("Whatever here"); then you use the variable "number" into a loop statement. You also need to create a counter (i use variable i) so that its like.. while(i<=number) System.out.print("*") or something. hope that helps.
__________________
On a budget Build? See my FAQ!! http://www.overclock.net/faqs/36946-...-system-i.html UPDATED MARCH 5th 07' NEW! Overclock.net Ping boosted CS:S Server - overclock.nuclearfallout.net:27015
Last edited by UberN00B : 10-13-09 at 06:41 PM |
||||||||||||||
|
|
|
|
#9 (permalink) | |||||||||||||||
|
Commodore 64
![]()
Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228
Rep: 89
![]() Unique Rep: 72
Trader Rating: 9
|
I suck at programming :P I'm into computer hardware design.
__________________
Quote:
Quote:
Xfire : gormogon : [OCN] Teh Root SteamID: [OCN] Teh Root
|
|||||||||||||||
|
|
|
|
|
#10 (permalink) | |||||||||||||||
|
.
![]() |
Quote:
Quote:
Code:
import java.util.*;
public class names {
static Scanner scanner = new Scanner(System.in);
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Enter A to print the name Alan: ");
String names = scanner.nextString();
if (names.equals("A") || names.equals("a"){
System.out.println("Alan");
}
}
}
__________________
Imaging with Windows PE Please keep the OCN Terms of Service in mind when posting.
Last edited by BiG O : 10-13-09 at 07:14 PM |
|||||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|