[JAVA] Output in multiples of 3

8/11 postscript ・ 3/0 is an error (ArithmeticException), but 0/3 is not an error

Basic rule: Multiples of 3 have "!!"

  1. Output the entered numerical values in order from 1.
  2. Output 1 in reverse
  3. Output 15 random numbers

Nabeatsu.java


import java.util.Random;
import java.util.Scanner;

public class Nabeatsu {

	public static void main(String[] args) {
		//Be stupid by multiples of 3
		Scanner scan = new Scanner(System.in);
		int number = scan.nextInt();
		for(int i = 1;i <= number; i++) {
			if(i % 3 == 0) 
				System.out.println(i + "!!");	
			else
				System.out.println(i);
		}
		for(int i = number;i > 0; i--) {  //In reverse order
			if(i % 3 == 0) 
				System.out.println(i + "!!");	
			else
				System.out.println(i);
		}

		Random random = new Random();
		int i = 0;
		while(i<15) {
			int ran = random.nextInt(500);
			if(ran % 3 == 0) {
				System.out.println(ran+ "!!");	
				i++;
			}else {
				System.out.println(ran);
				i++;

			}
		}
	}
}


Recommended Posts

Output in multiples of 3
Output triangle in Ruby
Format of the log output by Tomcat itself in Tomcat 8
Implementation of gzip in java
Judgment of fractions in Ruby
Summary of 2020 programming learning output
Pitfalls of WebTarget.queryParam () in JAX-RS
Implementation of HashMap in kotlin
Order of route evaluation in Spark
Introduction of javaFX in Eclipse (April 2020)
Basics of sending Gmail in Ruby
Output JavaScript in Thymeleaf 3 without escaping
Implementation of ls command in Ruby
Differences in split methods of StringUtils
Implementation of asynchronous processing in Tomcat
Mixed Western calendar output in Java
String output method memo in Ruby
Log output to file in Java
Output JUnit test report in Maven
How to output a list of strings in JSF as comma-separated strings
Log output of WebServiceTemplate request / response
List of types added in Java 9
Order of processing in the program
Implementation of like function in Java
Number of digits in numeric item
Types of exceptions in business systems
[Java] I participated in ABC-188 of Atcorder.
Extract elements of array / extract in reverse order-java
Get the result of POST in Java
Byte size of boolean type in JavaVM
Put Kanban in Docker of Raspberry Pi 3
Acquisition of article information in ruby ​​scraping
Directory information of DEFAULT_CERT_FILE in Mac ruby 2.0.0
[GCD] Basics of parallel programming in Swift
The identity of params [: id] in rails
Implementation of multi-tenant asynchronous processing in Tomcat
Output Notes document as XML document in Java
Output HTTP header of google-http-client to log
[rails] List of actions defined in Controller
Summary of root classes in various languages
Summary of hashes and symbols in Ruby
The story of AppClip support in Anyca
Output Date in Java in ISO 8601 extended format
Find an approximation of cosx in Swift
[Ruby] Classification and usage of loops in Ruby
Unexpected behavior of default message in org.springframework.context.MessageSource.getMessage ()
The story of writing Java in Emacs
FindBugs in Gradle doesn't output results in HTML
Role of JSP in Web application [Java]
English translation of Pleiades All in One
Write the movement of Rakefile in the runbook
Discrimination of Enums in Java 7 and above
File output bean as JSON in spring