0% found this document useful (0 votes)
11 views1 page

Java Programs for Basic Input and Output

The document contains four complete Java programs. The first program prints integers from 1 to 100 that are divisible by seven, the second reverses a user-input line, the third capitalizes all alphabetic characters in a user-input line, and the fourth performs basic arithmetic operations based on user input. Each program utilizes the Scanner class for user input and demonstrates different functionalities in Java.

Uploaded by

Tek wel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Java Programs for Basic Input and Output

The document contains four complete Java programs. The first program prints integers from 1 to 100 that are divisible by seven, the second reverses a user-input line, the third capitalizes all alphabetic characters in a user-input line, and the fourth performs basic arithmetic operations based on user input. Each program utilizes the Scanner class for user input and demonstrates different functionalities in Java.

Uploaded by

Tek wel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Write a complete program that prints out all integers from one to 100 which are divisible by
seven.
Answer:
```java
for (int i = 1; i <= 100; i++) {
if (i % 7 == 0) [Link](i);
}
```

2. Write a complete program that prompts the user to type a line of input, and then prints the
same line out with characters reversed.
Answer:
```java
Scanner sc = new Scanner([Link]);
String line = [Link]();
[Link](new StringBuilder(line).reverse().toString());
```

3. Write a complete program that prompts the user to type a line of input, and then prints the
same line out with alphabetic characters capitalised.
Answer:
```java
Scanner sc = new Scanner([Link]);
[Link]([Link]().toUpperCase());
```

4. Write a complete program that prompts the user to print a single positive integer number
followed by a space followed by a single operator followed by a space followed by another
single positive integer number, and then prints out the result.
Answer:
```java
Scanner sc = new Scanner([Link]);
int a = [Link]();
String op = [Link]();
int b = [Link]();
switch (op) {
case "+": [Link](a+b); break;
case "-": [Link](a-b); break;
case "*": [Link](a*b); break;
case "/": [Link](a/b); break;
}
```

You might also like