JAVA
Getting Started:
Output, Main Method:
1. Write a statement that prints Hello, world to the screen.
System.out.println("Hello, world") ;
2. Write a complete main method that prints Hello, world to the screen.
public static void main (String[] args)
{
System.out.println("Hello, world") ;
}
3. Suppose your name was Alan Turing. Write a statement that would print your last name, followed by a comma, followed by a space and your first name.
System.out.println("Turing, Alan") ;
4. Suppose your name was George Gershwin. Write a complete main method that would print your last name, followed by a comma, followed by a space and your first name.
public static void main (String[] args)
{
System.out.println("Gershwin, George") ;
}
More Output:
1. Given an integer variable count, write a statement that displays the value of count on the screen. Do not display anything else on the screen -- just the value of count.
Example: If the value of count were 194, then:
194
(with no other characters) would be displayed on the screen.
System.out.println(count);
2. Given a floating point variable fraction , write a statement that displays the value of fraction on the screen. Do not display anything else on the screen-- just the value of fraction.
Example: If the value of fraction were 2.667, then the output of your code would be:
2.667
on a line by itself (with no other characters).
System.out.println(fraction) ;
3. The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything.
Given an integer variable i and a floating-point variable f, that have already been given values, write a statement that writes both of their values to standard output in the following format:
i=value-of-i f=value-of-f
System.out.println("i="+i+" f="+f) ;
Declarations:
Basics:
1. Declare a variable populationChange, suitable for holding numbers like -593142 and 8930522.
int populationChange ;
2. Declare a variable x, suitable for storing values like 3.14159 and 6.02E23.
double x ;
Initialization:
1. Declare an integer variable cardsInHand and initialize it to 13.
int cardsInHand = 13;
2. Declare a variable temperature and initialize it to 98.6.
Instructor's notes: Declaring floating-point numbers can be done with either type float or type double. Of the two, you should use double, since it gives you more precision.
double temperature = 98.6;
3. Declare a variable precise and initialize it to the value 1.09388641.
double precise = 1.09388641;
Programs:
1. Write a complete program whose class name is Hello and that displays Hello, world on the screen.
public class Hello
{
public static void main (String[] args)
{
System.out.println("Hello, world");
}
}
Thank you so much!
ReplyDeleteThank you for your help
ReplyDeletethank you
ReplyDeleteit is not working
ReplyDeleteit says
Remarks:
⇒ Unexpected identifiers: Main, Public, args, main, static, string
⇒ Identifiers with case errors: system
⇒ Possible keyword case errors: Public
⇒ There is no need for a main method. Just write a statement, not a method, class or program.
⇒ There is no need to define a class here. Just write a statement, not a method, class or program.
⇒ You have to send your print or println message to System.out.
The Council agrees that:
⇒ I haven't yet seen a correct solution that uses: [ ]
⇒ I haven't yet seen a correct solution that uses: class
⇒ I haven't yet seen a correct solution that uses: public
Want More Hints? Hear From Other Voices
COMPILER ERROR MESSAGES
CTest.java:5: error: not a statement
Public class Main{
^
CTest.java:5: error: ';' expected
1 public class CTest {
2
3 public static void main(String[] s) {
4
5 Public class Main{
6 public static void main(string[]args{
7 system.out.println("Hello,World1");
8 }
9 }
10
11
12 }
13 }